package ar.edu.itba.it.paw.web.converter;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import ar.edu.itba.it.paw.domain.Category;
import ar.edu.itba.it.paw.repo.CategoryRepo;


@Component
public class CategoryConverter implements Converter<String, Category>{

	CategoryRepo repository;
	
	@Autowired
	public CategoryConverter( CategoryRepo repository){
		this.repository = repository;
	}
	
	@Override
	public Category convert(String source) {
		if(source.equals("0") || source.equals("")){
			return null;
		}
		return repository.getCategory(Integer.valueOf(source));
	}
	
}
